package com.koron.housing.contract.service.impl;


import com.koron.housing.contract.bean.po.HousingContractBill;
import com.koron.housing.contract.bean.vo.HousingContractBillVO;
import com.koron.housing.contract.mapper.HousingContractBillMapper;
import com.koron.housing.contract.service.HousingContractBillService;
import org.apache.commons.collections4.CollectionUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 发票报销(HousingContractBill)表服务实现类
 *
 * @author jzp
 * @since 2022-03-07 14:45:17
 */
@Service("billService")
public class HousingContractBillServiceImpl implements HousingContractBillService {

    /**
     * 通过ID查询单条数据
     */
    @Override
    @TaskAnnotation("getById")
    public HousingContractBill getById(SessionFactory factory, String id) {
        HousingContractBillMapper mapper = factory.getMapper(HousingContractBillMapper.class);
        return mapper.selectById(id);
    }

    /**
     * 查询所有数据
     */
    @Override
    @TaskAnnotation("list")
    public List<HousingContractBill> list(SessionFactory factory, HousingContractBill housingContractBill) {
        HousingContractBillMapper mapper = factory.getMapper(HousingContractBillMapper.class);
        return mapper.selectList(housingContractBill);
    }

    @Override
    @TaskAnnotation("listByContractId")
    public List<HousingContractBillVO> listByContractId(SessionFactory factory, String contractId) {
        HousingContractBillMapper mapper = factory.getMapper(HousingContractBillMapper.class);
        HousingContractBill housingContractBill = new HousingContractBill();
        housingContractBill.setContractId(contractId);
        return mapper.selectVoAllList(housingContractBill);
    }

    /**
     * 新增数据
     */
    @Override
    @TaskAnnotation("save")
    public boolean save(SessionFactory factory, HousingContractBill housingContractBill) {
        HousingContractBillMapper mapper = factory.getMapper(HousingContractBillMapper.class);
        return mapper.insertOrUpdate(housingContractBill) > 0;
    }

    @Override
    @TaskAnnotation("saveBatch")
    public boolean saveBatch(SessionFactory factory, List<HousingContractBill> housingContractBills) {
        if (CollectionUtils.isEmpty(housingContractBills)) {
            return false;
        }
        HousingContractBillMapper mapper = factory.getMapper(HousingContractBillMapper.class);
        return mapper.insertOrUpdateBatch(housingContractBills) > 0;
    }

    /**
     * 修改数据
     */
    @Override
    @TaskAnnotation("update")
    public boolean update(SessionFactory factory, HousingContractBill housingContractBill) {
        HousingContractBillMapper mapper = factory.getMapper(HousingContractBillMapper.class);
        return mapper.update(housingContractBill) > 0;
    }

    /**
     * 通过主键删除数据
     */
    @Override
    @TaskAnnotation("deleteById")
    public boolean deleteById(SessionFactory factory, String id) {
        HousingContractBillMapper mapper = factory.getMapper(HousingContractBillMapper.class);
        return mapper.hidden(id) > 0;
    }
}
